package com.iknight.theory.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.iknight.theory.api.TeLinePoleService;
import com.iknight.theory.mapper.TeLineConsMapper;
import com.iknight.theory.mapper.TeLinePoleMapper;
import com.iknight.theory.model.TELineConsModel;
import com.iknight.theory.model.TELinePoleModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class TeLinePoleServiceImpl implements TeLinePoleService<TELinePoleModel, String> {
    @Autowired
    private TeLinePoleMapper<TELinePoleModel, String> teLinePoleMapper;

    @Override
    public void save(TELinePoleModel record) {
        if (null == teLinePoleMapper.selectOne(record.getPole_id())) {
            teLinePoleMapper.insert(record);
        } else {
            teLinePoleMapper.update(record);
        }
    }

    @Override
    public void delete(String pkey) {
        teLinePoleMapper.delete(pkey);
    }

    @Override
    public TELinePoleModel selectOne(String pkey) {
        return teLinePoleMapper.selectOne(pkey);
    }

    @Override
    public PageInfo<TELinePoleModel> selectPage(Map<String, Object> params, int pageStart, int pageSize) {
//        return null;
        PageHelper.startPage(pageStart, pageSize, true);
        List<TELinePoleModel> result = teLinePoleMapper.selectByCond(params);
        PageInfo<TELinePoleModel> page = new PageInfo<>(result);
        return page;
    }

    @Override
    public void batchSave(List<TELinePoleModel> entities) {
        for (TELinePoleModel entity : entities) {
            this.save(entity);
        }
    }
}
